package com.rado.tf.gui.navigation;

import com.rado.tf.gui.MainUI;
import com.rado.tf.gui.event.UIEventTypes;
import com.rado.tf.gui.view.application.IApplicationView;
import com.rado.tf.gui.view.dashboard.impl.DashboardViewImpl;
import com.rado.tf.gui.view.newGroups.impl.NewGroupsViewImpl;
import com.rado.tf.gui.view.sampleValidation.impl.SampleValidationViewImpl;
import com.rado.tf.gui.view.userList.impl.UserListViewImpl;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by parado on 14.03.14.
 */
@Component(NavigationPlugin.BEAN_NAME)
public class NavigationPlugin
{
   public static final String BEAN_NAME = "navigationPlugin";

   @Resource
   private IApplicationView applicationView;

   private ApplicationContext context;

   public void init()
   {
      MainUI ui = MainUI.get();
      context = ui.getUiContext();
      Navigator navigator = new Navigator(ui, applicationView.getBodyContainer());
      ui.setNavigator(navigator);
      for (String entry : MenuEntries.entries)
      {
         navigator.addView(entry, (View) context.getBean(entry));
      }
   }

   public void handleMenuSelection(UIEventTypes type)
   {
      Navigator navigator = MainUI.get().getNavigator();
      if (UIEventTypes.MENU_DASHBOARD_SELECTED == type)
      {
         navigator.navigateTo(DashboardViewImpl.BEAN_NAME);
      }
      else if (UIEventTypes.MENU_NEW_GROUPS_SELECTED == type)
      {
         navigator.navigateTo(NewGroupsViewImpl.BEAN_NAME);
      }
      else if (UIEventTypes.MENU_USER_LIST_SELECTED == type)
      {
         navigator.navigateTo(UserListViewImpl.BEAN_NAME);
      }
      else if (UIEventTypes.MENU_SAMPLE_VALIDATION_SELECTED == type)
      {
         navigator.navigateTo(SampleValidationViewImpl.BEAN_NAME);
      }
   }
}
